package com.huashi.dealer.modular.business.order.param;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huashi.dealer.commonEntity.StoreUser;
import com.huashi.dealer.commonEntity.User;
import com.huashi.dealer.core.util.TimeUtil;
import com.huashi.dealer.modular.business.order.enums.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单列表视图对象
 *
 * @author 谭陈强
 * @since 2025-07-30
 */
@Data
@Schema(description = "订单列表视图对象")
public class OrderListVo {

    @Schema(description = "订单ID")
    private Long orderId;

    @Schema(description = "订单号")
    private String orderNo;

    @Schema(description = "商品总金额(不含优惠折扣)")
    private BigDecimal totalPrice;

    @Schema(description = "订单金额(含优惠折扣)")
    private BigDecimal orderPrice;

    @Schema(description = "优惠券id")
    private Long couponId;

    @Schema(description = "优惠券抵扣金额")
    private BigDecimal couponMoney;

    @Schema(description = "积分抵扣金额")
    private BigDecimal pointsMoney;

    @Schema(description = "积分抵扣数量")
    private Integer pointsNum;

    @Schema(description = "实际付款金额(包含运费)")
    private BigDecimal payPrice;

    @Schema(description = "后台修改的订单金额（差价）")
    private BigDecimal updatePrice;

    @Schema(description = "后台修改的订单金额（差价）VO实体类")
    private UpdatePriceVo updatePriceVo;

    @Schema(description = "买家留言")
    private String buyerRemark;

    @Schema(description = "支付方式")
    private int payType;

    @Schema(description = "支付方式VO实体类")
    private PayTypeVo payTypeVo;

    @Schema(description = "付款状态")
    private int payStatus;

    @Schema(description = "付款状态Vo")
    private PayStatusVo payStatusVo;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "付款时间")
    private Long payTime;

    @Schema(description = "配送方式")
    private int deliveryType;

    @Schema(description = "配送方式VO")
    private DeliveryTypeVo deliveryTypeVo;

    @Schema(description = "自提门店id")
    private Long extractShopId;

    @Schema(description = "核销店员id")
    private Long extractClerkId;

    @Schema(description = "运费金额")
    private BigDecimal expressPrice;

    @Schema(description = "快递公司ID")
    private Long expressId;

    @Schema(description = "快递公司名称")
    private String expressCompany;

    @Schema(description = "快递单号")
    private String expressNo;

    @Schema(description = "订单状态")
    private String stateText;

    @Schema(description = "发货状态")
    private int deliveryStatus;

    @Schema(description = "发货状态Vo")
    private DeliveryStatusVo deliveryStatusVo;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "发货时间")
    private Long deliveryTime;

    @Schema(description = "收货状态")
    private int receiptStatus;

    @Schema(description = "收货状态Vo")
    private ReceiptStatusVo receiptStatusVo;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "收货时间")
    private Long receiptTime;

    @Schema(description = "经销商信息")
    private User user;

    @Schema(description = "订单状态")
    private int orderStatus;

    @Schema(description = "订单状态Vo")
    private OrderStatusVo orderStatusVo;

    @Schema(description = "审核状态")
    private int auditStatus;

    @Schema(description = "审核状态Vo")
    private AuditStatusVo auditStatusVo;

    @Schema(description = "订单商品列表")
    private List<OrderGoodsVo> goodsList;

    @Schema(description = "用户信息")
    private UserInfoVo userInfo;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建时间")
    private Long createTime;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新时间")
    private Long updateTime;

    public LocalDateTime getReceiptTime() {
        return TimeUtil.changeToLocalDateTime(receiptTime);
    }
    public LocalDateTime getDeliveryTime() {
        return TimeUtil.changeToLocalDateTime(deliveryTime);
    }
    public LocalDateTime getCreateTime() {
        return TimeUtil.changeToLocalDateTime(createTime);
    }
    public LocalDateTime getUpdateTime() {
        return TimeUtil.changeToLocalDateTime(updateTime);
    }
    public LocalDateTime getPayTime() {
        return TimeUtil.changeToLocalDateTime(payTime);
    }


    public void setPayStatus(int payStatus) {
        this.payStatus = payStatus;
        initPayStatusVo();
    }

    private void initPayStatusVo() {
        if (payStatusVo == null) {
            payStatusVo = new PayStatusVo();
        }
        payStatusVo.setValue(payStatus);
        payStatusVo.setText(PayStatusEnum.getNameByValue(payStatus));
    }

    public void setPayType(int payType) {
        this.payType = payType;
        initPayTypeVo();
    }

    private void initPayTypeVo() {
        if (payTypeVo == null) {
            payTypeVo = new PayTypeVo();
        }
        payTypeVo.setValue(payType);
        payTypeVo.setText(PayTypeEnum.getNameByValue(payType));
    }

    public void setDeliveryType(int deliveryType) {
        this.deliveryType = deliveryType;
        initDeliveryTypeVo();
    }

    private void initDeliveryTypeVo() {
        if (deliveryTypeVo == null) {
            deliveryTypeVo = new DeliveryTypeVo();
        }
        deliveryTypeVo.setValue(deliveryType);
        deliveryTypeVo.setText(DeliveryTypeEnum.getNameByValue(deliveryType));
    }

    public void setDeliveryStatus(int deliveryStatus) {
        this.deliveryStatus = deliveryStatus;
        initDeliveryStatusVo();
    }

    private void initDeliveryStatusVo() {
        if (deliveryStatusVo == null) {
            deliveryStatusVo = new DeliveryStatusVo();
        }
        deliveryStatusVo.setValue(deliveryStatus);
        deliveryStatusVo.setText(DeliveryStatusEnum.getNameByValue(deliveryStatus));
    }

    public void setReceiptStatus(int receiptStatus) {
        this.receiptStatus = receiptStatus;
        initReceiptStatusVo();
    }

    private void initReceiptStatusVo() {
        if (receiptStatusVo == null) {
            receiptStatusVo = new ReceiptStatusVo();
        }
        receiptStatusVo.setValue(receiptStatus);
        receiptStatusVo.setText(ReceiptStatusEnum.getNameByValue(receiptStatus));
    }

    public void setOrderStatus(int orderStatus) {
        this.orderStatus = orderStatus;
        initOrderStatusVo();
    }

    private void initOrderStatusVo() {
        if (orderStatusVo == null) {
            orderStatusVo = new OrderStatusVo();
        }
        orderStatusVo.setValue(orderStatus);
        orderStatusVo.setText(OrderStatusEnum.getNameByValue(orderStatus));
        this.stateText=OrderStatusEnum.getNameByValue(orderStatus);
    }

    public void setAuditStatus(int auditStatus) {
        this.auditStatus = auditStatus;
        initAuditStatusVo();
    }

    private void initAuditStatusVo() {
        if (auditStatusVo == null) {
            auditStatusVo = new AuditStatusVo();
        }
        auditStatusVo.setValue(auditStatus);
        auditStatusVo.setText(AuditStatusEnum.getNameByValue(auditStatus));
    }

    public void setUpdatePrice(BigDecimal updatePrice) {
        this.updatePrice = updatePrice;
        initUpdatePriceVo();
    }

    private void initUpdatePriceVo() {
        if (updatePriceVo == null) {
            updatePriceVo = new UpdatePriceVo();
        }
        updatePriceVo.setSymbol(updatePrice.compareTo(BigDecimal.ZERO) < 0 ? "-" : "+");
        updatePriceVo.setValue(updatePrice.abs().toString());
    }

    /**
     * 支付方式视图对象
     */
    @Data
    @Schema(description = "支付方式")
    public static class PayTypeVo {
        @Schema(description = "支付方式文本")
        private String text;

        @Schema(description = "支付方式值")
        private Integer value;
    }

    /**
     * 付款状态视图对象
     */
    @Data
    @Schema(description = "付款状态")
    public static class PayStatusVo {
        @Schema(description = "付款状态文本")
        private String text;

        @Schema(description = "付款状态值")
        private Integer value;
    }

    /**
     * 配送方式视图对象
     */
    @Data
    @Schema(description = "配送方式")
    public static class DeliveryTypeVo {
        @Schema(description = "配送方式文本")
        private String text;

        @Schema(description = "配送方式值")
        private Integer value;
    }

    /**
     * 发货状态视图对象
     */
    @Data
    @Schema(description = "发货状态")
    public static class DeliveryStatusVo {
        @Schema(description = "发货状态文本")
        private String text;

        @Schema(description = "发货状态值")
        private Integer value;
    }

    /**
     * 收货状态视图对象
     */
    @Data
    @Schema(description = "收货状态")
    public static class ReceiptStatusVo {
        @Schema(description = "收货状态文本")
        private String text;

        @Schema(description = "收货状态值")
        private Integer value;
    }

    /**
     * 订单状态视图对象
     */
    @Data
    @Schema(description = "订单状态")
    public static class OrderStatusVo {
        @Schema(description = "订单状态文本")
        private String text;

        @Schema(description = "订单状态值")
        private Integer value;
    }

    /**
     * 审核状态视图对象
     */
    @Data
    @Schema(description = "审核状态")
    public static class AuditStatusVo {
        @Schema(description = "审核状态文本")
        private String text;

        @Schema(description = "审核状态值")
        private Integer value;
    }


    /**
     * 用户信息视图对象
     */
    @Data
    @Schema(description = "用户信息")
    public static class UserInfoVo {
        @Schema(description = "用户ID")
        private Long userId;

        @Schema(description = "用户昵称")
        private String nickName;

        @Schema(description = "用户头像")
        private String avatarUrl;

        @Schema(description = "用户手机号")
        private String mobile;
    }

    /**
     * 修改价格视图对象
     */
    @Data
    @Schema(description = "后台修改的订单金额（差价）")
    public static class UpdatePriceVo {
        @Schema(description = "符号")
        private String symbol;

        @Schema(description = "金额")
        private String value;
    }
} 